package de.slothsoft.network;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

@SuppressWarnings("nls")
public class ClientsPanel extends JPanel {

	private static final long serialVersionUID = 1L;

	private JTabbedPane clientsPane;
	private int currentClient = 1;

	public ClientsPanel() {
		createLayout();
	}

	private void createLayout() {
		setBorder(BorderFactory.createTitledBorder("Clients"));
		setLayout(new BorderLayout());

		JPanel parent = new JPanel();
		createTopControls(parent);
		add(parent, BorderLayout.NORTH);

		this.clientsPane = new JTabbedPane();
		add(this.clientsPane, BorderLayout.CENTER);
	}

	private void createTopControls(JPanel parent) {
		parent.setLayout(new FlowLayout(FlowLayout.LEFT));

		JButton button = new JButton("Neuer Client");
		button.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				createClient();
			}
		});
		parent.add(button);
	}

	protected void createClient() {
		this.clientsPane.addTab("Client " + this.currentClient++, new ClientPanel());
	}
}
